package javabase.schoolwork.day6_10;

/**
 * @author fance
 * @date 2018/6/10 10:25
 */
class GetMoneyThread extends Thread {
    private double getMoney;
    private Account account;

    public GetMoneyThread(String name, double getMoney, Account account) {
        super(name);
        this.getMoney = getMoney;
        this.account = account;
    }

    @Override
    public void run() {
        synchronized (account) {
        account.setMoney(account.getMoney() - getMoney);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("取钱后余额为：" + account.getMoney());
        }
    }
}
public class BankDemo {
    public static void main(String[] args) {
    Account account = new Account("123",1000);
        for (int i = 0; i < 10; i++) {
            GetMoneyThread thread = new GetMoneyThread(String.valueOf(i),100,account);
            thread.start();
        }

    }
}
